#ifndef __LIST_H
#define __LIST_H

struct list {
    struct list *prev, *next;
};

#undef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

#undef container_of
#define container_of(ptr, type, member) ((type *)((char *)ptr - offsetof(type,member)))

#undef list_for_each_entry_universal
#define list_for_each_entry_universal(type, pos, n, head, member)    \
    for(pos = container_of((head)->next, type, member),              \
        n = container_of(pos->member.next, type, member);            \
        &pos->member != (head);                                      \
        pos = n, n = container_of(n->member.next, type, member))

void list_add_head(struct list *_new, struct list *head);
void list_add_tail(struct list *_new, struct list *head);
void list_del(struct list *entry);
int list_is_last(const struct list *entry, const struct list *head);
int list_empty(const struct list *head);

#endif/*__LIST_H*/
